package com.compomics.cellmotionsimulator.gui;

import com.compomics.cellmotionsimulator.CellMotionSimulator;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
* Created by Lennart on 30/10/2014.
*/
public class CellMotionFrame extends JFrame {
    private CellMotionPanel iPanel = null;


    public CellMotionFrame(CellMotionSimulator aCMS) {
        super("Cell motion frame");
        this.setLayout(new BorderLayout());
        this.setBackground(Color.white);
        this.addWindowListener(new WindowAdapter() {
            /**
             * Invoked when a window is in the process of being closed.
             * The close operation can be overridden at this point.
             */
            public void windowClosing(WindowEvent e) {
                e.getWindow().setVisible(false);
                e.getWindow().dispose();
                System.out.println("\nThank you for using the Cell Motion Simulator!\n");
                System.exit(0);
            }
        });

        iPanel = new CellMotionPanel(aCMS);
        this.getContentPane().add(iPanel, BorderLayout.CENTER);

        // Determine the size of the screen.
        Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();

        // Position the frame in the middle of the screen.
        this.setMinimumSize(this.getPreferredSize());
        Dimension preferredSize = this.getPreferredSize();
        int x = (int)Math.round((screensize.getWidth() - preferredSize.getWidth()) / 2);
        int y = (int)Math.round((screensize.getWidth()-preferredSize.getWidth())/2);

    }
}
